Basic Tree Stats

Basic Tree Stats#

Project Description#

In this project, I will be using tree inventory data from Ottawa Open Data to practice data analysis and data visualization work in Python.

Contains information licensed under the Open Government Licence – City of Ottawa

Hide code cell source
import pandas as pd
import plotly.express as px

# Contains information licensed under the Open Government Licence – City of Ottawa
trees = pd.read_csv("data/tree_inventory.csv")
Hide code cell output
/tmp/ipykernel_16268/3050844523.py:5: DtypeWarning: Columns (4,16) have mixed types. Specify dtype option on import or set low_memory=False.
  trees = pd.read_csv("data/tree_inventory.csv")
# Data Cleanup / Transform

# basic extraction of species
trees["species_general"] = trees["SPECIES"].str.split(" ").str[0]

trees.head()
X Y OBJECTID WARD ADDNUM ADDSTR LTLOCATION RDLOCATION FACILITY EDGETREE PATHTRAIL SPECIES DBH TREATMENT EABTAGNUMBER DEDTAGNUMBER SAP_ID PROGRAM species_general
0 -8.424807e+06 5.689722e+06 63887 12 151 CHAPEL ST Front NaN 0.0 0.0 0.0 Linden Littleleaf 45.0 NaN NaN NaN 8113295 NaN Linden
1 -8.424802e+06 5.689690e+06 63888 12 151 CHAPEL ST Front NaN 0.0 0.0 0.0 Maple Manitoba 66.0 NaN NaN NaN 8113293 NaN Maple
2 -8.424815e+06 5.689689e+06 63889 12 151 CHAPEL ST Front NaN 0.0 0.0 0.0 Maple Manitoba 62.0 NaN NaN NaN 8113292 NaN Maple
3 -8.424782e+06 5.689649e+06 63890 12 153 CHAPEL ST Front NaN 0.0 0.0 0.0 Linden Littleleaf 26.0 NaN NaN NaN 8113306 NaN Linden
4 -8.424769e+06 5.689638e+06 63891 12 153 CHAPEL ST Front NaN 0.0 0.0 0.0 Linden Littleleaf 31.0 NaN NaN NaN 8113305 NaN Linden
species_ward_count = pd.DataFrame({'count' : trees.groupby(["species_general", "WARD"])["species_general"].count()}).reset_index()
species_ward_count

fig = px.bar(species_ward_count, x="WARD", y="count", color="species_general", title="Species by Ward")
fig.show()